""" Endpoint

Description

Request

Response data

Response errors

"""
from comando import AbstractValidationCommand, Comando, ComandoResult
from google.appengine.api import mail
from google.appengine.api.mail import EmailMessage

class RedirectCommand(AbstractValidationCommand):

    URL = "url"
    
    def required(self):
        return frozenset([RedirectCommand.URL])
    def optional(self):
        return frozenset([])    
    def doExecute(self):
        result = ComandoResult()
        result.setLocation(self.getParam(RedirectCommand.URL))

        return result
""" Endpoint

Description

Request

Response data

Response errors

"""
class EmailCommand(AbstractValidationCommand):

    TO = "to"

    SUBJECT = "subject"

    CC = "cc"

    BODY = "body"

    SENDER = "sender"
    def required(self):
        return frozenset([EmailCommand.SENDER, EmailCommand.SUBJECT, EmailCommand.BODY, EmailCommand.TO, EmailCommand.CC])
    def optional(self):
        return frozenset([])
    def doExecute(self):
        
        result = ComandoResult()
        
        emailMessage = EmailMessage()
        emailMessage.sender = self.getParam(EmailCommand.SENDER)
        emailMessage.subject = self.getParam(EmailCommand.SUBBJECT)
        emailMessage.body =  self.getParam(EmailCommand.BODY)
        emailMessage.to =  self.getParam(EmailCommand.TO)
        emailMessage.cc =  self.getParam(EmailCommand.CC)
        emailMessage.send()
        
        result.setStatus(1)
        
        return result